#include <iostream>
#include <string>
#include <cstdio>
using namespace std;

char s1[1005],s2[1005];
int len1, len2, len;
int c1[300], c2[300];

int main()
{
	int i, j, t;	
//	freopen("fin.txt","r",stdin);
//	freopen("fout.txt", "w", stdout);
	while (1)
	{
		if (!gets(s1)) break;
		if (!gets(s2)) break;
		len1 = strlen(s1);
		len2 = strlen(s2);
		memset(c1, 0, sizeof(c1));
		memset(c2, 0, sizeof(c2));
		
		for (i=0; i<len1; ++i)
			c1[s1[i]]++;
		for (i=0; i<len2; ++i)
			c2[s2[i]]++;
		for (i=0; i<300; ++i)
			if (c1[i] && c2[i])
			{
				t = c1[i] < c2[i] ? c1[i] : c2[i];
				for (j=1; j<=t; ++j)
					printf("%c", i);
			}
		printf("\n");
		
	}
	
	
	return 0;
}


